<?php

namespace App\Admin\Controllers;

use App\Models\Bank;
use App\Models\BankList;
use App\Models\Resume;
use App\Models\Withdraw;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Illuminate\Support\Facades\Request;
use Redis;

class WithdrawController extends AdminController
{
    protected $title = '提现列表';
    protected $status = [
        '-1' => '拒绝',
        '0' => '待审核',
        '1' => '同意'
    ];

    protected function grid()
    {
        $grid = new Grid(new Withdraw());
        $grid->column('id', 'Id号');
        $grid->column('uid', '姓名')->display(function ($uid) {
            $name = Resume::where('uid', $uid)->value('realname');
            return $name;
        });
        $grid->column('money', '金额');
        $grid->column('status', '状态')->using($this->status);
        $grid->column('addtime', '时间');

        $grid->model()->orderBy('id', 'desc');

        $grid->actions(function ($actions) {
            $actions->disableEdit();
            $actions->disableDelete();
        });

        $grid->disableCreateButton();
        $grid->batchActions(function ($batch) {
            $batch->disabledelete();
        });

        return $grid;
    }

    protected function detail($id)
    {
        $show = new Show(Withdraw::findOrFail($id));

        $show->field('id', __('Id号'));
        $show->field('uid', __('姓名'))->as(function ($uid) {
            $name = Resume::where('uid', $uid)->value('realname');
            return $name;
        });
        $show->field('money', __('金额'));
        $show->field('bank_name', __('银行名称'))->as(function () {
            //银行卡信息
            $bankId = Bank::where('id', $this->bank_id)->value('bank_id');
            $bankName = BankList::where('id', $bankId)->value('bank_name');
            return $bankName;
        });
        $show->field('bank_number', __('银行卡号'))->as(function () {
            //银行卡信息
            $bankNumber = Bank::where('id', $this->bank_id)->value('bank_number');
            return $bankNumber;
        });
        $show->field('status', __('状态'))->using($this->status);
        $show->field('addtime', '提现时间');

        $show->panel()
            ->tools(function ($tools) {
                $tools->disableEdit();
                $tools->disableDelete();
            });

        return $show;
    }

}